package cn.gwm.flink.streaming.dwm.charge.assist;

import cn.gwm.flink.streaming.dwm.charge.model.ChargeConstant;
import cn.gwm.flink.streaming.dwm.charge.model.ChargeEvConstant;
import cn.gwm.flink.streaming.dwm.charge.model.ChargePhevConstant;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName ChargeSteadyFieldFactory
 * @Description
 * @Author LiangGuang
 * @Date 2023/05/10 10:04
 */
public class ChargeSteadyFieldUtil {

    public static final String FIELD_STEADY_SUFFIX = StrUtil.DASHED + "steadyVal";
    public static final String FIELD_STEADY_FLAG = StrUtil.DASHED + "steadyFlag";

    private static final Map<String, List<String>> steadyFieldMap = new ConcurrentHashMap<>();

    private static final Map<String, Object> connectMap = new HashMap<>();

    static {
        chargeField(ChargeEvConstant.getInstance());
        chargeField(ChargePhevConstant.getInstance());
    }

    public static List<String> chargeFieldList(String key) {
        return Collections.unmodifiableList(steadyFieldMap.get(key));
    }

    public static Boolean connectField(String key) {
        return connectMap.containsKey(key);
    }


    private static void chargeField(ChargeConstant constant) {
        List<String> list = new ArrayList<>();
        list.add(constant.getObcConnectStsEv());
        list.add(constant.getObcCclineConnectSts());
        // 快充
        list.add(constant.getBmsDcchrgConnect());
        // 充电
        list.add(constant.getBmsChrgSts());
        // 电流
        list.add(constant.getBmsBattCurr());
        // 周期信号，充电模式
        list.add("PlugChrgnMode");
        list.add("IntellgntChrgnModResp");


        steadyFieldMap.put(constant.getPowerType(), list);

        connectMap.put(constant.getObcConnectStsEv(), null);
        connectMap.put(constant.getObcCclineConnectSts(), null);
        connectMap.put(constant.getBmsDcchrgConnect(), null);


        final List<String> suffixList = CollectionUtil.newArrayList();
        list.forEach(item -> {
            suffixList.add(item + FIELD_STEADY_SUFFIX);
        });
        steadyFieldMap.put(constant.getPowerType() + FIELD_STEADY_SUFFIX, suffixList);

        final List<String> flagList = CollectionUtil.newArrayList();
        list.forEach(item -> {
            flagList.add(item + FIELD_STEADY_FLAG);
        });
        steadyFieldMap.put(constant.getPowerType() + FIELD_STEADY_FLAG, suffixList);

    }

}
